<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class SyntaxSuggest::CodeLine - syntax_suggest: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-from_source">::from_source</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-empty-3F">#empty?</a>
    <li ><a href="#method-i-hidden-3F">#hidden?</a>
    <li ><a href="#method-i-ignore_newline_not_beg-3F">#ignore_newline_not_beg?</a>
    <li ><a href="#method-i-indent_index">#indent_index</a>
    <li ><a href="#method-i-is_end-3F">#is_end?</a>
    <li ><a href="#method-i-is_kw-3F">#is_kw?</a>
    <li ><a href="#method-i-mark_invisible">#mark_invisible</a>
    <li ><a href="#method-i-not_empty-3F">#not_empty?</a>
    <li ><a href="#method-i-set_kw_end">#set_kw_end</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-trailing_slash-3F">#trailing_slash?</a>
    <li ><a href="#method-i-visible-3F">#visible?</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-SyntaxSuggest::CodeLine">
    <h1 id="class-SyntaxSuggest::CodeLine" class="class">
      class SyntaxSuggest::CodeLine
    </h1>

    <section class="description">
    
<p>Represents a single line of code of a given source file</p>

<p>This object contains metadata about the line such as amount of indentation, if it is empty or not, and lexical data, such as if it has an ‘end` or a keyword in it.</p>

<p>Visibility of lines can be toggled off. Marking a line as invisible indicates that it should not be used for syntax checks. It’s functionally the same as commenting it out.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">line</span> = <span class="ruby-constant">CodeLine</span>.<span class="ruby-identifier">from_source</span>(<span class="ruby-string">&quot;def foo\n&quot;</span>).<span class="ruby-identifier">first</span>
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">number</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span>
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">visible?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">mark_invisible</span>
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">visible?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="TRAILING_SLASH">TRAILING_SLASH
          <dd>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-indent" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">indent</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-index" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">index</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-lex" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">lex</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-line" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">line</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-line_number" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">line_number</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-number" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">number</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-original" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">original</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>When the code line is marked invisible we retain the original value of it’s line this is useful for debugging and for showing extra context</p>

<p><a href="DisplayCodeWithLineNumbers.html"><code>DisplayCodeWithLineNumbers</code></a> will render all lines given to it, not just visible lines, it uses the original method to obtain them.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-from_source" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">from_source</span><span
                                class="method-args">(source, lines: nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of <a href="CodeLine.html"><code>CodeLine</code></a> objects from the source string</p>

                              <div class="method-source-code" id="from_source-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">from_source</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">lines:</span> <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">lines</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">lines</span>
  <span class="ruby-identifier">lex_array_for_line</span> = <span class="ruby-constant">LexAll</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">source:</span> <span class="ruby-identifier">source</span>, <span class="ruby-value">source_lines:</span> <span class="ruby-identifier">lines</span>).<span class="ruby-identifier">each_with_object</span>(<span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span>, <span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = [] }) { <span class="ruby-operator">|</span><span class="ruby-identifier">lex</span>, <span class="ruby-identifier">hash</span><span class="ruby-operator">|</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">lex</span>.<span class="ruby-identifier">line</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">lex</span> }
  <span class="ruby-identifier">lines</span>.<span class="ruby-identifier">map</span>.<span class="ruby-identifier">with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">CodeLine</span>.<span class="ruby-identifier">new</span>(
      <span class="ruby-value">line:</span> <span class="ruby-identifier">line</span>,
      <span class="ruby-value">index:</span> <span class="ruby-identifier">index</span>,
      <span class="ruby-value">lex:</span> <span class="ruby-identifier">lex_array_for_line</span>[<span class="ruby-identifier">index</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
    )
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(line:, index:, lex:)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 42</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-value">line:</span>, <span class="ruby-value">index:</span>, <span class="ruby-value">lex:</span>)
  <span class="ruby-ivar">@lex</span> = <span class="ruby-identifier">lex</span>
  <span class="ruby-ivar">@line</span> = <span class="ruby-identifier">line</span>
  <span class="ruby-ivar">@index</span> = <span class="ruby-identifier">index</span>
  <span class="ruby-ivar">@original</span> = <span class="ruby-identifier">line</span>
  <span class="ruby-ivar">@line_number</span> = <span class="ruby-ivar">@index</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">strip_line</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">strip_line</span>.<span class="ruby-identifier">lstrip!</span>

  <span class="ruby-ivar">@indent</span> = <span class="ruby-keyword">if</span> (<span class="ruby-ivar">@empty</span> = <span class="ruby-identifier">strip_line</span>.<span class="ruby-identifier">empty?</span>)
    <span class="ruby-identifier">line</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span> <span class="ruby-comment"># Newline removed from strip_line is not &quot;whitespace&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">line</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">strip_line</span>.<span class="ruby-identifier">length</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">set_kw_end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3D-3E" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">&lt;=&gt;</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Comparison operator, needed for equality and sorting</p>

                              <div class="method-source-code" id="3C-3D-3E-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 150</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-identifier">index</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">index</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-empty-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">empty?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>An ‘empty?` line is one that was originally left empty in the source code, while a “hidden” line is one that we’ve since marked as “invisible”</p>

                              <div class="method-source-code" id="empty-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 115</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">empty?</span>
  <span class="ruby-ivar">@empty</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hidden-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hidden?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Opposite or ‘visible?` (note: different than `empty?`)</p>

                              <div class="method-source-code" id="hidden-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 108</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hidden?</span>
  <span class="ruby-operator">!</span><span class="ruby-identifier">visible?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ignore_newline_not_beg-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">ignore_newline_not_beg?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <dl class="rdoc-list label-list"><dt>Not stable API
<dd>
<p>Lines that have a ‘on_ignored_nl` type token and NOT a `BEG` type seem to be a good proxy for the ability to join multiple lines into one.</p>

<p>This predicate method is used to determine when those two criteria have been met.</p>

<p>The one known case this doesn’t handle is:</p>

<pre class="ruby"><span class="ruby-constant">Ripper</span>.<span class="ruby-identifier">lex</span> <span class="ruby-identifier">&lt;&lt;~EOM</span>
<span class="ruby-value">  a &amp;&amp;
   b ||
   c
</span><span class="ruby-identifier">EOM</span>
</pre>

<p>For some reason this introduces ‘on_ignore_newline` but with BEG type</p>
</dd></dl>

                              <div class="method-source-code" id="ignore_newline_not_beg-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 172</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ignore_newline_not_beg?</span>
  <span class="ruby-ivar">@ignore_newline_not_beg</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-indent_index" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">indent_index</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Used for stable sort via indentation level</p>

<p>Ruby’s sort is not “stable” meaning that when multiple elements have the same value, they are not guaranteed to return in the same order they were put in.</p>

<p>So when multiple code lines have the same indentation level, they’re sorted by their index value which is unique and consistent.</p>

<p>This is mostly needed for consistency of the test suite</p>

                              <div class="method-source-code" id="indent_index-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">indent_index</span>
  <span class="ruby-ivar">@indent_index</span> <span class="ruby-operator">||=</span> [<span class="ruby-identifier">indent</span>, <span class="ruby-identifier">index</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-is_end-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">is_end?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if the code line is determined to contain an ‘end` keyword</p>

                              <div class="method-source-code" id="is_end-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 87</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">is_end?</span>
  <span class="ruby-ivar">@is_end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-is_kw-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">is_kw?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if the code line is determined to contain a keyword that matches with an ‘end`</p>

<p>For example: ‘def`, `do`, `begin`, `ensure`, etc.</p>

                              <div class="method-source-code" id="is_kw-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 81</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">is_kw?</span>
  <span class="ruby-ivar">@is_kw</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mark_invisible" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mark_invisible</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Used to hide lines</p>

<p>The search alorithm will group lines into blocks then if those blocks are determined to represent valid code they will be hidden</p>

                              <div class="method-source-code" id="mark_invisible-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 96</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mark_invisible</span>
  <span class="ruby-ivar">@line</span> = <span class="ruby-string">&quot;&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-not_empty-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">not_empty?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Opposite of ‘empty?` (note: different than `visible?`)</p>

                              <div class="method-source-code" id="not_empty-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 120</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">not_empty?</span>
  <span class="ruby-operator">!</span><span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Renders the given line</p>

<p>Also allows us to represent source code as an array of code lines.</p>

<p>When we have an array of code line elements calling ‘join` on the array will call `to_s` on each element, which essentially converts it back into it’s original source string.</p>

                              <div class="method-source-code" id="to_s-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 133</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_s</span>
  <span class="ruby-identifier">line</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-trailing_slash-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trailing_slash?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Determines if the given line has a trailing slash</p>

<pre>lines = CodeLine.from_source(&lt;&lt;~EOM)
  it &quot;foo&quot; \
EOM
expect(lines.first.trailing_slash?).to eq(true)</pre>

                              <div class="method-source-code" id="trailing_slash-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 183</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">trailing_slash?</span>
  <span class="ruby-identifier">last</span> = <span class="ruby-ivar">@lex</span>.<span class="ruby-identifier">last</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">last</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">last</span>.<span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value">:on_sp</span>

  <span class="ruby-identifier">last</span>.<span class="ruby-identifier">token</span> <span class="ruby-operator">==</span> <span class="ruby-constant">TRAILING_SLASH</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-visible-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">visible?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Means the line was marked as “invisible” Confusingly, “empty” lines are visible…they just don’t contain any source code other than a newline (“n”).</p>

                              <div class="method-source-code" id="visible-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 103</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">visible?</span>
  <span class="ruby-operator">!</span><span class="ruby-identifier">line</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-set_kw_end" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_kw_end</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Endless method detection</p>

<p>From <a href="https://github.com/ruby/irb/commit/826ae909c9c93a2ddca6f9cfcd9c94dbf53d44ab">github.com/ruby/irb/commit/826ae909c9c93a2ddca6f9cfcd9c94dbf53d44ab</a> Detecting a “oneliner” seems to need a state machine. This can be done by looking mostly at the “state” (last value):</p>

<pre>ENDFN -&gt; BEG (token = &#39;=&#39; ) -&gt; END</pre>

                              <div class="method-source-code" id="set_kw_end-source">
            <pre><span class="ruby-comment"># File syntax_suggest/code_line.rb, line 199</span>
        <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_kw_end</span>
  <span class="ruby-identifier">oneliner_count</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">in_oneliner_def</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-identifier">kw_count</span> = <span class="ruby-value">0</span>
  <span class="ruby-identifier">end_count</span> = <span class="ruby-value">0</span>

  <span class="ruby-ivar">@ignore_newline_not_beg</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@lex</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">lex</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">kw_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">is_kw?</span>
    <span class="ruby-identifier">end_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">is_end?</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value">:on_ignored_nl</span>
      <span class="ruby-ivar">@ignore_newline_not_beg</span> = <span class="ruby-operator">!</span><span class="ruby-identifier">lex</span>.<span class="ruby-identifier">expr_beg?</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">in_oneliner_def</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">in_oneliner_def</span> = <span class="ruby-value">:ENDFN</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">state</span>.<span class="ruby-identifier">allbits?</span>(<span class="ruby-constant">Ripper</span><span class="ruby-operator">::</span><span class="ruby-constant">EXPR_ENDFN</span>)
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">state</span>.<span class="ruby-identifier">allbits?</span>(<span class="ruby-constant">Ripper</span><span class="ruby-operator">::</span><span class="ruby-constant">EXPR_ENDFN</span>)
      <span class="ruby-comment"># Continue</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">state</span>.<span class="ruby-identifier">allbits?</span>(<span class="ruby-constant">Ripper</span><span class="ruby-operator">::</span><span class="ruby-constant">EXPR_BEG</span>)
      <span class="ruby-identifier">in_oneliner_def</span> = <span class="ruby-value">:BODY</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">token</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;=&quot;</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">lex</span>.<span class="ruby-identifier">state</span>.<span class="ruby-identifier">allbits?</span>(<span class="ruby-constant">Ripper</span><span class="ruby-operator">::</span><span class="ruby-constant">EXPR_END</span>)
      <span class="ruby-comment"># We found an endless method, count it</span>
      <span class="ruby-identifier">oneliner_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">in_oneliner_def</span> <span class="ruby-operator">==</span> <span class="ruby-value">:BODY</span>

      <span class="ruby-identifier">in_oneliner_def</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">in_oneliner_def</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">kw_count</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">oneliner_count</span>

  <span class="ruby-ivar">@is_kw</span> = (<span class="ruby-identifier">kw_count</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">end_count</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
  <span class="ruby-ivar">@is_end</span> = (<span class="ruby-identifier">end_count</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">kw_count</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

